package relay

import (
	"gitee.com/ameise84/e3utils/str_conv"
	jsoniter "github.com/json-iterator/go"
	"servers/app/client/conn"
	"servers/app/client/metas"
	"servers/models/define"
	"servers/models/error_code"
	"servers/utils"
)

func Recharge(c conn.Client, amount int64) define.ErrorCode {
	ac := c.GetAccountInfo()
	jsonRsp := metas.BaseRsp{}
	var (
		SrcOrder  = "order"
		SrcAmount = "amount"
		SrcFlag   = "flag"
	)
	rsp, err := c.DoRequest(conn.ReqPost, "/demo-api/use-bank", map[string]string{
		define.WebBusinessId: str_conv.ToString(ac.Bid),
		define.WebAccount:    ac.Account,
		SrcOrder:             utils.RandString(16),
		SrcAmount:            str_conv.ToString(amount),
		SrcFlag:              "0",
	})
	if err != nil {
		return error_code.ErrorCodeUnknown
	}
	_ = jsoniter.UnmarshalFromString(rsp, &jsonRsp)
	return jsonRsp.Code
}
